package com.pj.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.pj.entity.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "登录")
@RestController
@RequestMapping("/user/")
public class UserController {

    // 测试登录，浏览器访问： http://localhost:8081/user/doLogin?username=zhang&password=123456

    @ApiOperation(value = "登录接口")
    @PostMapping("doLogin")
    public String doLogin(User user) {
        //获取数据库数据
        // 此处仅作模拟示例，真实项目需要从数据库中查询数据进行比对
        if ("li".equals(user.getUserName()) && "123456".equals(user.getPassWord())) {
            StpUtil.login(10001);
            return "登录成功";
        }
        return "登录失败";
    }

    // 查询登录状态，浏览器访问： http://localhost:8081/user/isLogin
    @RequestMapping("isLogin")
    @ApiOperation(value = "查询登录")
    public String isLogin() {
        return "当前会话是否登录：" + StpUtil.isLogin();
    }

}
